package com.winning.pmph.config;

import com.winning.pmph.utils.Const;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 线程池的配置
 */
@EnableAsync
@Configuration
public class TaskExecutorConfig {
    @Bean
    public TaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(Const.FIXED_THREAD_POOL_SIZE);
        taskExecutor.setMaxPoolSize(Const.FIXED_THREAD_POOL_SIZE * 2);
        taskExecutor.setThreadNamePrefix("thread-pool-");
        taskExecutor.initialize();
        return taskExecutor;
    }
}